package top.kaoshanji.p3ch12a;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.List;

/**
 * 代码清单-p3ch12a-385页a：为包含通配符的参数化类型提供类型信息
 * author kaoshanji
 * ^_^
 * create time 2025/2/6 14:39
 */
public class ObjectFactory {

    private static final Logger logger = LogManager.getLogger(ObjectFactory.class);

    public static void main(String[] args) throws Exception {
        logger.info("...代码清单-p3ch12a-385页a：为包含通配符的参数化类型提供类型信息...");

        new ObjectFactory().test();
    }

    public static <T> T create(Class<T> interfaceType) throws Exception {
        String className = searchForClassName();
        Class<?> clazz = Class.forName(className);
        return interfaceType.cast(clazz.newInstance());
    }

    public void test() throws Exception {
        List list = ObjectFactory.create(List.class);
        System.out.println(list);
    }

    private static String searchForClassName() {
        return "";
    }

}
